//
//  MainController.swift
//  Weibo
//
//  Created by 明丽 on 16/1/11.
//  Copyright © 2016年 明丽. All rights reserved.
//

import UIKit

class MainController: UITabBarController {
    
    
    @objc private func piusButton(){
        
        print("我是按钮点击事件")
        
        let comp = composeViewController()
        //添加导航控制器
        let nav = UINavigationController(rootViewController: comp)
        //model出控制器
        presentViewController(nav, animated: true, completion: nil)
        
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = MainTabbar()
        
        setValue(mainTabbar, forKey: "tabBar")
        
        mainTabbar.plusBtn.addTarget(self, action: "piusButton", forControlEvents: .TouchUpInside)
        
        
        addChildViewControllers()
        
    }
    
    private   func  addChildViewControllers(){
        
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", titleName: "首页")
        //消息
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", titleName: "消息")
        //发现
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", titleName: "发现")
        //我
        addChildViewController(profileTableViewController(), imageName: "tabbar_profile", titleName: "我")
        
        
        
    }
    
    
    private   func addChildViewController(vc : UIViewController, imageName : String ,titleName : String){
        vc.tabBarItem.image = UIImage(named: imageName)
        self.tabBar.tintColor = UIColor.orangeColor()
        
        vc.title = titleName
        let nav = BaseNavViewController(rootViewController: vc)
        //添加子控制器
        addChildViewController(nav)
        
        
        
        
        
        
    }
    
}
